package org.example.system.controller.question;

import jakarta.validation.Valid;
import org.example.common.core.controller.BaseController;
import org.example.common.core.domain.Result;
import org.example.common.core.domain.ResultTable;
import org.example.system.domain.question.dto.QuestionAddDTO;
import org.example.system.domain.question.dto.QuestionEditDTO;
import org.example.system.domain.question.dto.QuestionQueryDTO;
import org.example.system.domain.question.vo.QuestionDetailVO;
import org.example.system.service.question.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController()
@RequestMapping("/question")
public class QuestionController extends BaseController {

    @Autowired
    private QuestionService questionService;

    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId) {
        return Result.ok(questionService.detail(questionId));
    }

    @GetMapping("/list")
    public ResultTable list(QuestionQueryDTO questionQueryDTO) {
        return getTable(questionService.list(questionQueryDTO));
    }

    @PostMapping("/add")
    public Result<Void> add(@RequestBody @Valid QuestionAddDTO questionDTO) {
        return toResult(questionService.add(questionDTO));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@RequestBody @Valid QuestionEditDTO questionEditDTO) {
        return toResult(questionService.edit(questionEditDTO));
    }

    @DeleteMapping("/delete")
    public Result<Void> delete(Long questionId) {
        return toResult(questionService.delete(questionId));
    }
}
